#!/bin/bash
ipaddr=$FASTDFS_IPADDR
old="com.ikingtech.ch116221"
new_val=127.0.0.1:22122
index=0

#日志记录头部
for ip in $ipaddr;
do
  if [ $index == 0 ]; then
  # shellcheck disable=SC1068
  new_val=$ip"\\n"
  else
  # shellcheck disable=SC1068
  new_val=$new_val"tracker_server="$ip"\\n"
  fi
# shellcheck disable=SC2219
let index+=1
done

sed -i "s#$old#$new_val\\n#g" /etc/fdfs/client.conf
sed -i "s#$old#$new_val\\n#g" /etc/fdfs/storage.conf
sed -i "s#$old#$new_val\\n#g" /etc/fdfs/mod_fastdfs.conf
#sed -i "s#$old#$new_val#g" /etc/fdfs/client.conf
#sed -i "s#$old#$new_val#g" /etc/fdfs/storage.conf
#sed -i "s#$old#$new_val#g" /etc/fdfs/mod_fastdfs.conf

cat  /etc/fdfs/client.conf > /etc/fdfs/client.txt
cat  /etc/fdfs/storage.conf >  /etc/fdfs/storage.txt
cat  /etc/fdfs/mod_fastdfs.conf > /etc/fdfs/mod_fastdfs.txt

mv /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.t
cp /etc/fdfs/nginx.conf /usr/local/nginx/conf

echo "start trackerd"
/etc/init.d/fdfs_trackerd start

echo "start storage"
/etc/init.d/fdfs_storaged start

echo "start nginx"
/usr/local/nginx/sbin/nginx 

tail -f  /dev/null